// source --> https://tudorcollector.com/wp-content/themes/tudor-theme/js/script.js?ver=1 (function ($) { $(document).on('click', '.collectioncategory .type', function (event) { event.preventDefault(); $('.collectioncategory li').removeClass('active'); $(this).closest('li').addClass('active'); var colType = $(this).attr('value'); var colUrl = ajax_var.colUrl; //console.log(window.location.pathname); $.ajax({ // URL to which request is sent. url: ajax_var.ajaxurl, // specifies how contents of data option are sent to the server. // `post` indicates that we are submitting the data. type: 'post', // data to be sent to the server. data: { // a function defined in functions.php hooked to this action (with `wp_ajax_nopriv_` and/or `wp_ajax_` prefixed) will run. action: 'collectionLoop', // stores the value of `data-id` attribute of the clicked link in a variable. post_id: $(this).data('id'), cat_var: $(this).attr('value'), }, // pre-reqeust callback function. beforeSend: function () { $('#collectionitems1').html(''); }, // function to be called if the request succeeds. // `response` is data returned from the server. success: function (response) { var stateObj = { collectionType: colType }; var singleColUrl = colUrl + colType; //console.log(colType); //console.log(colUrl); history.pushState(stateObj, "collection", singleColUrl); //history.pushState(stateObj, "collection", colType); $('.collectionitems').slick('unslick'); //$('#collectionitems1').hide().html(response).fadeIn('slow'); $('#collectionitems1').hide().html(response).show(); document.addEventListener( 'load', function(event){ var elm = event.target; if( elm.nodeName.toLowerCase() === 'img' && $(elm).closest('#collectionitems1').length && !$(elm).hasClass('loaded')){ // or any other filtering condition console.log('image loaded yo'); $(elm).addClass('loaded'); if($('#collectionitems1 img.loaded').length === $('#collectionitems1 img').length) { console.log('all images loaded'); $('.collectionitems').slick({ initialSlide:0, infinite: false, slidesToShow: 1, slidesToScroll: 1, autoplay: false, centerMode:false, pauseOnHover:false, dots: true, customPaging : function(slider, i) { var thumb = $(slider.$slides[i]).data(); return ''+(i+1)+''; }, arrows: true, centerPadding: '0px', nextArrow: '
' , prevArrow: '
' , autoplaySpeed: 5000, adaptiveHeight:true }); } } }, true // Capture event ); //custom function showing current slide var $status = $('.pagingInfo'); var $slickElement = $('.slider'); $slickElement.on('init reInit afterChange', function (event, slick, currentSlide, nextSlide) { //currentSlide is undefined on init -- set it to 0 in this case (currentSlide is 0 based) var i = (currentSlide ? currentSlide : 0) + 1; $status.text(i + '/' + slick.slideCount); }); } }); window.onpopstate = function(event) { var parts = window.location.href.split('/'); var lastSegment = parts.pop() || parts.pop(); // handle potential trailing slash if(lastSegment == 'the-collection'){ lastSegment = 'watches'; } //console.log(lastSegment); $('.collectioncategory li').removeClass('active'); //$(this).closest('li').addClass('active'); $('.collectioncategory li').each(function(index){ var aVal = $('.collectioncategory li').eq(index).find('a').attr('value'); if(aVal == lastSegment){ $(this).closest('li').addClass('active'); } }); var colType = $(this).attr('value'); var colUrl = ajax_var.colUrl; //console.log(window.location.pathname); $.ajax({ // URL to which request is sent. url: ajax_var.ajaxurl, // specifies how contents of data option are sent to the server. // `post` indicates that we are submitting the data. type: 'post', // data to be sent to the server. data: { // a function defined in functions.php hooked to this action (with `wp_ajax_nopriv_` and/or `wp_ajax_` prefixed) will run. action: 'collectionLoop', // stores the value of `data-id` attribute of the clicked link in a variable. post_id: $(this).data('id'), cat_var: lastSegment, }, // pre-reqeust callback function. beforeSend: function () { $('#collectionitems1').html(''); }, // function to be called if the request succeeds. // `response` is data returned from the server. success: function (response) { var stateObj = { collectionType: colType }; var singleColUrl = colUrl + colType; $('.collectionitems').slick('unslick'); //$('#collectionitems1').hide().html(response).fadeIn('slow'); $('#collectionitems1').hide().html(response).show(); if(colType == 'watches' || colType == 'accessories' || colType == 'techinfo' || colType == 'serial'){ $('#collectionitems1').slick({ initialSlide:0, infinite: false, slidesToShow: 1, slidesToScroll: 1, autoplay: false, centerMode:false, pauseOnHover:false, dots: true, customPaging : function(slider, i) { var thumb = $(slider.$slides[i]).data(); return ''+(i+1)+''; }, arrows: true, centerPadding: '0px', nextArrow: '
' , prevArrow: '
' , autoplaySpeed: 5000, adaptiveHeight:true }); } //custom function showing current slide var $status = $('.pagingInfo'); var $slickElement = $('.slider'); $slickElement.on('init reInit afterChange', function (event, slick, currentSlide, nextSlide) { //currentSlide is undefined on init -- set it to 0 in this case (currentSlide is 0 based) var i = (currentSlide ? currentSlide : 0) + 1; $status.text(i + '/' + slick.slideCount); }); } }); }; }); })(jQuery); //single ajax post (function ($) { var scrollheight = $(window).scrollTop(); var savedscrollheight; $(window).scroll(function(){ scrollheight = $(window).scrollTop(); if(scrollheight > 0) { $( "body" ).addClass("notop"); } else{ $( "body" ).removeClass("notop"); } }); $(document).on('click', '.collectionitems li a.noserial', function (event) { event.preventDefault(); var postid = $(this).attr('data-id'); var posthref = $(this).attr('href'); var colType = $(this).attr('val'); var colUrl = ajax_var.colUrl; //console.log(colType); $.ajax({ // URL to which request is sent. url: ajax_var.ajaxurl, // specifies how contents of data option are sent to the server. // `post` indicates that we are submitting the data. type: 'post', // data to be sent to the server. data: { // a function defined in functions.php hooked to this action (with `wp_ajax_nopriv_` and/or `wp_ajax_` prefixed) will run. action: 'collectionSingleAjax', // stores the value of `data-id` attribute of the clicked link in a variable. post_id: $(this).data('id'), }, context: document.body, // pre-reqeust callback function. beforeSend: function () { $('#customlightbox').html(''); $('.customlightbox').addClass(colType); savedscrollheight = scrollheight; $('body').removeClass('menuon'); $('body').removeClass('searchon'); $('body').addClass('customlightboxon'); $('main').css({'top': -savedscrollheight}); window.scrollTo(0,0); } }).done(function (data) { document.addEventListener( 'load', function(event){ var elm = event.target; if( elm.nodeName.toLowerCase() === 'img' && $(elm).closest('.collectiondetail').length && !$(elm).hasClass('loaded')){ // or any other filtering condition console.log('image loaded'); $(elm).addClass('loaded'); if($('.collectiondetail img.loaded').length === $('.collectiondetail img').length) { console.log("All images loaded!") if($('.collectiondetail .multiphoto').length > 0){ $('.collectiondetail .multiphoto').slick({ initialSlide:0, infinite: true, slidesToShow: 1, slidesToScroll: 1, autoplay: true, centerMode:false, pauseOnHover:false, arrows: true, centerPadding: '0px', nextArrow: '
' , prevArrow: '
' , autoplaySpeed: 5000, adaptiveHeight:true }); } } } }, true // Capture event ); var stateObj = { collectionType: 'postid' }; history.pushState(stateObj, "collection", posthref); //$('#customlightbox').hide().html(data).fadeIn(1000); $('#customlightbox').hide().html(data).show(); if($('#customlightbox .imgzoom').length > 0){ $('#customlightbox .collectiondetail').slickLightbox({ background: 'rgba(15, 65, 134, 0.80)', caption: 'caption', itemSelector: '.imgzoom img', src: 'data-img', lazy: true, useHistoryApi: true, layouts: { closeButton: '' } }); } $(document).on('click', '.closingbtn, .customlightbox .shield', function() { $('.customlightbox article').removeClass('customloaded'); var stateObj = { collectionType: 'pageCol' }; var colUrl = ajax_var.colUrl; var singleColUrl = colUrl + colType; //console.log(colType); //console.log(colUrl); history.pushState(stateObj, "collection", singleColUrl); $('.customlightbox .paper').css({'top': -(scrollheight-savedscrollheight)}); $('body').removeClass('customlightboxon'); $('main').css({'top': 0}); setTimeout(function(){ $('.customlightbox .paper').css({'top': '0'}); }, 700); window.scrollTo(0,savedscrollheight) // return false; }); window.onpopstate = function(event) { $('.customlightbox .paper').css({'top': -(scrollheight-savedscrollheight)}); $('body').removeClass('customlightboxon'); $('main').css({'top': 0}); setTimeout(function(){ $('.customlightbox .paper').css({'top': '0'}); }, 700); window.scrollTo(0,savedscrollheight) }; }); }); })(jQuery);